package com.mars.mybatis.common;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Transient;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;

public class BaseEntity {

	/**
	 * 搜索关键字
	 */
	@Transient @JsonIgnore @JSONField(serialize=false)
	private String keyword ;
	
	/**
	 * 查询的字段
	 */
	@Transient @JsonIgnore @JSONField(serialize=false)
	private List<String> fileds ;
	
	/**
	 * order by 排序集合
	 */
	@Transient @JsonIgnore @JSONField(serialize=false)
	private List<FieldOrder> fieldOrders = new ArrayList<FieldOrder>();
	
	/**
	 * 添加排序
	 * @param field 排序字段
	 * @param isAsc 排序类型（true: ASC，false: DESC）
	 */
	@Transient
	public void setOrderBy(String field, boolean isAsc) {
		fieldOrders.add(new FieldOrder(field, isAsc?"asc":"desc")) ;
	}
	
	public List<FieldOrder> getFieldOrders() {
		return fieldOrders;
	}

	public void setFieldOrders(List<FieldOrder> fieldOrders) {
		this.fieldOrders = fieldOrders;
	}

	public class FieldOrder {
		private String field ;
		private String order ;
		public FieldOrder(String field, String order) {
			super();
			this.field = field;
			this.order = order;
		}
		public String getField() {
			return field;
		}
		public void setField(String field) {
			this.field = field;
		}
		public String getOrder() {
			return order;
		}
		public void setOrder(String order) {
			this.order = order;
		}
	}
	
	public List<String> getFileds() {
		return fileds;
	}

	public void setFileds(List<String> fileds) {
		this.fileds = fileds;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}
	
}
